﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lidgren.Network;

namespace Server
{
    class Program
    {
        static void Main(string[] args)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("PokeMania");
            config.Port = 9000;

            NetServer server = new NetServer(config);
            server.Start();

            int i = 0;
            while (server.Status == NetPeerStatus.Running)
            {
                Console.WriteLine("Listening for Package " + ++i);

                NetIncomingMessage msg;
                while ((msg = server.ReadMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.ConnectionApproval:
                            msg.SenderConnection.Approve();
                            break;
                        case NetIncomingMessageType.ConnectionLatencyUpdated:
                        case NetIncomingMessageType.Data:
                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.DiscoveryRequest:
                        case NetIncomingMessageType.DiscoveryResponse:
                        case NetIncomingMessageType.Error:
                        case NetIncomingMessageType.ErrorMessage:
                        case NetIncomingMessageType.NatIntroductionSuccess:
                        case NetIncomingMessageType.Receipt:
                        case NetIncomingMessageType.StatusChanged:
                        case NetIncomingMessageType.UnconnectedData:
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                            Console.WriteLine(msg.ReadString());
                            break;
                        default:
                            Console.WriteLine("Unhandled Exception or Type: " + msg.MessageType);
                            break;
                    }

                    server.Recycle(msg);

                }
            }

            Console.ReadLine();

        }
    }
}
